import type { GlobConfig } from '/#/config';

import { getAppEnvConfig } from '/@/utils/env';

export const useGlobSetting = (): Readonly<GlobConfig> => {
  const { VITE_GLOB_APP_TITLE,
    VITE_GLOB_API_URL,
    VITE_GLOB_API_URL_PREFIX,
    VITE_GLOB_UPLOAD_URL,
    VITE_GLOB_BASE_URL,
    VITE_GLOB_USERNAME,
    VITE_GLOB_PASSWORD,
    VITE_GLOB_PRODUCT_TREE_NODE_ID,
    VITE_GLOB_SALE_TREE_NODE_ID,
    VITE_GLOB_MATERIAL_TREE_NODE_ID,
  } = getAppEnvConfig();
  // Take global configuration
  const glob: Readonly<GlobConfig> = {
    title: VITE_GLOB_APP_TITLE,
    apiUrl: VITE_GLOB_API_URL,
    shortName: VITE_GLOB_APP_TITLE.replace(/\s/g, '_').replace(/-/g, '_'),
    urlPrefix: VITE_GLOB_API_URL_PREFIX,
    uploadUrl: VITE_GLOB_UPLOAD_URL,
    baseUrl: VITE_GLOB_BASE_URL,
    usename: VITE_GLOB_USERNAME,
    password: VITE_GLOB_PASSWORD,
    productRootId: VITE_GLOB_PRODUCT_TREE_NODE_ID,
    saleRootId: VITE_GLOB_SALE_TREE_NODE_ID,
    materialRootId:VITE_GLOB_MATERIAL_TREE_NODE_ID,
  };
  return glob as Readonly<GlobConfig>;
};
